package com.jinguanjia.stock.web.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class IndexController {

	private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

	@Autowired
	private DiscoveryClient client;
	
	@RequestMapping(value = "/discovery", method = RequestMethod.GET)
	public Object discovery()
	{	
		List<String> list = client.getServices();  //获取注册中心的所有服务 
		List<ServiceInstance> srvList = client.getInstances("EUREKA-PROVIDER"); //获取名为MICROSERVICECLOUD-DEPT服务
		for (ServiceInstance element : srvList) {
			System.out.println(element.getServiceId() + "\t" + element.getHost() + "\t" + element.getPort() + "\t"
					+ element.getUri());
		}
		return this.client;
	}
	
	@RequestMapping("/hello")
    public String index() {
        System.out.println("index is called");
        return "Hello World";
    }
	
}
